$(function(){ 
	toLoadData();
}); 

function toLoadData(){
	var currPage=$("#currPage").val();
	var totalPage=$("#totalPage").val();
	var search=$("#search").val();
	$.ajax({
        url: basePath+"medicine/toSearchMedicineList.spring",
    	data:{search:search,
			currPage:currPage},
        type: "POST",
        dataType: 'json',
        cache: false,
        success: function (ret) {
        	var html="";
        	$("#showmedicine").html("");
        	$("#curr").html(ret.currPage);
			$("#total").html(ret.totalPage);
			$("#currPage").val(ret.currPage);
			$("#totalPage").val(ret.totalPage);
        	if(ret!=null){
        		
        		for(var i=0;i<ret.list.length;i++ ){
        			var data=ret.list[i];
        			html+="<li onclick=\"toReadDetail("+data.id+")\">";
        			html+="<p style=\" font-weight:bold;\">"+data.name+"</p>";
        			html+="<span>使用症状:";
        			html+="<p style=\"width: 100%;\">"+data.indications;
        			html+="</p></span>";
        			html+="<span>药品成分:";
        			html+="<p style=\"width: 100%;\">"+data.ingredient;
        			html+="</p></span>";
        			html+="<span>适应症:";
        			html+="<p style=\"width: 100%;\">"+data.effectType;
        			html+="</p></span>";
        			html+="<span>价格: <span style=\"color: red\">"+data.price;
        			html+="</span></span>";
        		}
        		$("#showmedicine").append(html);
        		
        	}
        }
    });
}

/**
 * 上一页
 */
function pre(){
	var totalPage=$("#totalPage").val();
	var currPage=$("#currPage").val();
	if(Number(currPage)==1){
		alert("已经是第一页");
	}else{
		var prePage=Number(currPage)-1;
		$("#currPage").val(prePage);
		loadData();
	}
}
/**
 * 下一页
 */
function next(){
	var totalPage=$("#totalPage").val();
	var currPage=$("#currPage").val();
	var nextPage=Number(currPage)+1;
	if(currPage>=totalPage){
		alert("已经是最后一页了");
	}else{
		$("#currPage").val(nextPage);
		loadData();
	}
}
/**
 * 搜索
 */
function toSearch(){
	toLoadData();
}
function toReadDetail(id){
	var url=basePath+"jsp/medicineDetail.jsp?id="+id;
window.location.href=url;
}